﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;

namespace XW.Utils
{
    public static class JsonHelper
    {
      
        public static string ToJson(object o)
        {
            return JsonConvert.SerializeObject(o);
        }
  
        public static T ToObject<T>(string s)
        {
            if (s.IsNullOrEmpty())
            {
                return default(T);
            }
            return JsonConvert.DeserializeObject<T>(s);
        }

        public static string GetValue(string s, string key)
        {
            return JsonConvert.DeserializeObject<Dictionary<string,string>>(s)[key];
        }
    }
}
